#include <bits/stdc++.h>
// 2025/03/19
// tag: 
// Author: Forever
using namespace std;

#pragma GCC -Ofast
using int64 = int64_t;

string s[100];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--){
        int n, m;
        cin >> n >> m;
        for (int i = 0; i < n; i++)
            cin >> s[i];
        int cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < n; i++){
            bool type = false;
            for (int j = 0; j < m; j++) 
                if (s[i][j] == '1')
                    type ^= true;
            if (type)
                cnt1++;
        }
        for (int i = 0; i < m; i++){
            bool type = false;
            for (int j = 0; j < n; j++)
                if (s[j][i] == '1')
                    type ^= true;
            if (type)
                cnt2++;
        }
        cout << max(cnt1, cnt2) << endl;
    }
    return 0;
}